package com.red.controller.user;

import com.red.dto.HomePageQueryDTO;
import com.red.dto.NotesUploadDTO;
import com.red.entity.NoteComments;
import com.red.entity.TravelNotes;
import com.red.result.PageResult;
import com.red.result.Result;
import com.red.service.TravelNotesService;
import com.red.vo.NotesVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/notes")
@ApiModel(value = "小记接口")
@Slf4j
public class TravelNotesController {
    @Autowired
    private TravelNotesService notesService;

    /**
     * 分页查询
     * @param dto
     * @return
     */
    @GetMapping("/notesPort")
    @ApiModelProperty("分页查询")
    public Result<PageResult> notesPort(HomePageQueryDTO dto){
        log.info("分页查询信息：{}",dto);
        PageResult pageResult = notesService.pageQuery(dto);
        return Result.success(pageResult);
    }

    /**
     * 上传小记内容
     * @param dto
     * @return
     */
    @PostMapping("/upload")
    @ApiModelProperty("上传小记内容")
    public Result uploadText(@RequestBody NotesUploadDTO dto){
        log.info("上传照片");
        notesService.uploadNote(dto);
        return Result.success();
    }

    /**
     * 根据ID删除小记
     * @param ids
     * @return
     */
    @DeleteMapping("/{ids}")
    @ApiModelProperty("根据ID删除此用户的小记内容")
    public Result deleteByIds(@PathVariable List<Long> ids){
        notesService.deleteByIds(ids);
        return Result.success();
    }


    /**
     * 给小记点赞
     * @param id
     * @return
     */
    @PutMapping("/like/{id}")
    @ApiModelProperty("给小记点赞")
    public Result noteLike(@PathVariable Long id){
        notesService.noteLike(id);
        return Result.success();
    }

    /**
     * 根据用户ID查询喜欢小记
     * @return
     */
    @GetMapping()
    @ApiModelProperty("根据用户ID查询喜欢小记")
    public Result<List<TravelNotes>> selectByUserId(){
        List<TravelNotes> list = notesService.selectByUserId();
        return Result.success(list);
    }

    /**
     * 根据ID查询小记
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiModelProperty("根据ID查询小记")
    public Result<NotesVO> selectById(@PathVariable Long id){
        NotesVO notesVO = notesService.selectById(id);
        return Result.success(notesVO);
    }

    /**
     * 根据用户id查询发布的小记
     * @return
     */
    @GetMapping("/publish")
    @ApiModelProperty("根据用户id查询发布的小记")
    public Result<List<NotesVO>> selectById(){
        List<NotesVO> list = notesService.selectAllByUserId();
        return Result.success(list);
    }

    /**
     * 发表评论
     * @param noteComments
     * @return
     */
    @PostMapping("/uploadComment")
    @ApiModelProperty("发表评论")
    public Result uploadComment(@RequestBody NoteComments noteComments){
        log.info("发表评论的实体 = {}",noteComments);
        notesService.uploadComment(noteComments);
        return Result.success();
    }
}
